package com.cqc.zhbjcqc.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.cqc.zhbjcqc.R;
import com.cqc.zhbjcqc.application.ImageLoaderOptions;
import com.cqc.zhbjcqc.bean.FragNewsItemBean;
import com.lidroid.xutils.BitmapUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by ${cqc} on 2016/9/29.
 */

public class FragNewsItemAdapter extends ListViewBaseAdapter<FragNewsItemBean.DataBean.NewsBean> {
    private List<FragNewsItemBean.DataBean.NewsBean> list;

    public FragNewsItemAdapter(Context context, List list) {
        super(context, list);
        this.list = list;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_frag_news_item, viewGroup, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ImageLoader.getInstance().displayImage(list.get(position).getListimage(), holder.iv_item, ImageLoaderOptions.list_options);
        holder.tv_title.setText(list.get(position).getTitle());
        holder.tv_time.setText(list.get(position).getPubdate());

        return convertView;
    }

    public class ViewHolder {
        public ImageView iv_item;
        public TextView tv_title;
        public TextView tv_time;
        public ImageView iv_comment;

        public ViewHolder(View itemView) {
            super();
            iv_item = (ImageView) itemView.findViewById(R.id.iv_item);
            tv_title = (TextView) itemView.findViewById(R.id.tv_title_item);
            tv_time = (TextView) itemView.findViewById(R.id.tv_time_item);
            iv_comment = (ImageView) itemView.findViewById(R.id.iv_comment_item);
        }
    }
}
